<template>
  <basic-dialog
    :visible.sync="recordVisable"
    :title="'转派记录'"
    :show-footer="false"
    :width="'60%'"
    :handleClose="handleCloseDialog"
    :handle-open="handleOpen"
  >
    <basic-table
      :loading="tableInfo.loading"
      :columns="tableInfo.columns"
      :dataSource="tableInfo.list"
      :pagination="pagination"
      :tableHeight="480"
      :showSelectCol="false"
      @pageChange="handlePageChange"
      @pageSizeChange="handlePageSizeChange"
    >
    </basic-table>
  </basic-dialog>
</template>
<script>
import BasicDialog from '@/components/BasicDialog';
import BasicTable from '@/components/supplier/BasicTable';
import BasicPage from '@/mixins/supplier/basicPage';
import { RECORD_TABLE_COLUMNS } from '../constants'
import { turnToSendRecordService } from '@api/supplier/returnVisteManage';

export default {
  name: 'RecordDialog',
  mixins: [BasicPage],
  components: {
    BasicDialog,
    BasicTable,
  },
  props: {
    recordVisable: {
      type: Boolean,
      default: false
    },
    supplierData: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data () {
    return {
      queryData: {},
      tableInfo: {
        list: [],
        columns: RECORD_TABLE_COLUMNS,
        loading: false
      }
    };
  },

  methods: {
    handleOpen () {
      this.queryData = this.supplierData;
      this.getTableData()
    },
    // 关闭弹框
    handleCloseDialog () {
      this.$emit('update:recordVisable', false);
    },
    async getTableData () {
      const res = await turnToSendRecordService(
        {
          supplierId: this.queryData.supplierId,
          ...this.pagination
        },
        state => { this.tableInfo.loading = state }
      )
      if (res) {
        const { records, total } = res.result;
        this.tableInfo.list = records;
        this.pagination.total = total;
      }
    },
  }
};
</script>
